<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %><!-- 数据库操作需要 -->        
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
		//获取参数，转换为相应的类型
		String RequestID=request.getParameter("RequestID");
		String Status=null;
		String AgreeOrNot=request.getParameter("AgreeOrNot");
		String CensorContent=request.getParameter("CensorContent");
		String Adminname=request.getParameter("Adminname");
		String AdminTime=request.getParameter("AdminTime");
		System.out.println(" RequestID:"+ RequestID+"AgreeOrNot:"+AgreeOrNot);
		if(AgreeOrNot.equals("同意"))
			Status="审核通过";
		else
			Status="审核未通过";
		String ID=null;
		//第一个java代码段查询数据
		try{
			Class.forName("org.h2.Driver");//加载驱动
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return;
		}
		String url="jdbc:h2:d:/CompanyCar/temp/mydbtest";
		Connection conn=null;

	//数据库连接与查询过程中可能会引发sql异常
	try {
		//获取数据库连接(url,username,password)			
		conn = DriverManager.getConnection(url,"sa","");
		//准备执行数据库插入，此处使用了?方式，比拼接字符串更清晰
		String sql="update CarRequest set AgreeOrNot=?,CensorContent=?,Adminname=?,AdminTime=?,Status=? where RequestID='"+RequestID+"' ";
		
		PreparedStatement pstmt=conn.prepareStatement(sql);
		//准备SQL执行;注意此处与Statement的不同
		pstmt.setString(1,AgreeOrNot);
		pstmt.setString(2,CensorContent);
		pstmt.setString(3,Adminname);
		pstmt.setString(4,AdminTime);
		pstmt.setString(5,Status);
		//执行数据库插入，获取结果集
		int result=pstmt.executeUpdate();
		//关闭表达式对象
		pstmt.close();			
		//关闭数据库			
		conn.close();			
		
	} catch (SQLException e) {
		e.printStackTrace();
	} finally{
		//防止数据库未正常关闭
		try{
			if (conn!=null && (!conn.isClosed())){
				conn.close();
			}
		}catch(SQLException e){
			e.printStackTrace();
		}
	}

	request.setAttribute("addok","1");

	request.getRequestDispatcher("/C-Use_Check.jsp").forward(request,response);
%>
</body>
</html>